#Q1.1

#Q1.2

#Create The Data and the Test Data For Q1.3

#Q1.3a #Here we can see that the Expected Optimism decrease as h go to 1. #When N=200 we see that the Expected Optimism lower then the Expected Optimism of N=50. #N=200 and lamda=5 give the lowest Expected Optimism Among all h = 0.2,0.5,1. #N=50 and lamda =5 give the highest Expected Optimism Among all h = 0.2,0.5,1.

## [1] "\nW= Whight of the Y in the model\n    x_1   x_2 ... x_n\nx_1 K()   k()     k(x_1,x_n)/(sum  K() in  line 1)\nx_2\nx_3\n.\n.\n.\nx_n\n\nvar( tset1[,2])#Calculate Sigma of the Y form the data \n"

#Q1.3b #Here we can see that the Error measurement(RMSE,MAE,R2) increaseas h go to 1.lamda have mach more effect in the Error measurement(RMSE,MAE,R2)then the number of the observition (N).Also there is teadeoff here if R2 is high then the rmse also highand if R2 is low then the rmse also low.

#Q1.3c #The Expected in-sample prediction error increase as h go to 1 . #N=200,lamda=5 create the highest Expected in-sample prediction error among all h =0.2,0.5,0.1. #N=50,lamda=1.5 create the lowest Expected in-sample prediction error among all h =0.2,0.5,0.1.

## [1] "Expected in-sample prediction error"

#Q1.3d ‘Calculate EPE’

#we can see that ’Estimate the out-of-sample expected prediction errorlower as h go to 1. #N=50,lamda=5 create the highest ’Estimate the out-of-sample expected prediction error. #N=50,lamda=1.5 create the lowest Expected in-sample prediction error. #Then i conclute that lamda have mach more effect on the Estimate the out-of-sample expected prediction error then the number of the observation (N).

## [1] "Estimate the out-of-sample expected prediction error EPE"

#Q1.4 Create the Quadratic Model

#Q1.4 Calculate Eop #N=200,lamda=5 create the lowest expected optimism [Eop] of regression functionamong the other N and lamda in the graph. #N=50,lamda=1.5 create the highest expected optimism [Eop] of regression function among the other N and lamda in the graph. we can see that lamda effect expected optimism [Eop] of regression function math more then the number of the observation (N)

#Q1.4 Calculate Cross-Validation #Here we can see the N=50,lamda=5 give the highest rmse but also the highest R2 and N=200,lamda=1.5 give the the highest rmse but also the lowest R2. #So we conclude there is trade-off between high R2 and lower rmse. #Also we can see that lamda have mach more effect on the Erorr measurement(RSE,MAE,R2) the number of the observation(N).

#Q1.4 Calculate in-sample expected error expected prediction error (EPE_in) #N=50,lamda=5 create the highest in-sample expected error expected prediction error. #N=50,lamda=1.5 create the highest in-sample expected error expected prediction error.

#from the graph i conclude that lamda have much more effect on the in-sample expected error expected prediction error then the number of the observation(N).

#Q1.4 Calculate out-of-sample expected prediction error (EPE) #N=50,lamda=5 create the lowest out-of-sample expected prediction error (EPE) #N=50,lamda=1.5 create the highest out-of-sample expected prediction error (EPE)

#from the graph i conclude that lamda have much more effect on the out-of-sample expected prediction error (EPE) then the number of the observation(N). #Also the out-of-sample expected prediction error (EPE) and thein-sample expected error expected prediction errorhave negative trad.

#Q2.1 #In the plot above we can see the a scatter plot of the number of daily new Covid cases.The regression line was fitted using kernel regression with a band-width of 14.The regression seems to be smooth and does not seem to capture much of the noise.

#Q2.2

#The plot above shows the daily change in rate of new Covid cases. We van see thatthe growth of the rate is slower than when the rate is dropping. Meaningwe have a steadyclimb and a more rapid fall. This could be do the fact, thatonce the number of new infections gotto a certain level, the country went in to lock-down and stopped the growth.

#Time sereis plot #This tome series plot decomposses an Additive model to its diffrernt componnents.We can see that the genral trend of the virus had two magor peaks.the random componnent we can see that the random part does not follow astochastic procces.meaning that the mean and variance of the random part is not steady over time.However if we were to split the data by the level of the trend we would see that for that time frame the random noise is stochastic

#Q_3

Best model for each voxel
alpha mse_min mse_1se lambda_min lambda_1se
Voxel_1 0.2 0.7241838 0.7612045 0.2769457 0.5829442
Voxle_2 1.0 0.8138093 0.8608769 0.0434315 0.1266052
Voxel_3 0.3 1.0024412 1.0052239 0.2427681 0.3522149

#In the table above, we see the best model for each voxel and some of thiere parametersand other stats. these results are from after running a ten fold croos-validation on each model. WE can see the the best response is for V1.

#In the plot above, we can see the mean mse across all voxels for every alpha.we can see that on average the model with the best response is the elastic modelwith alpha equal to 0.2.

#Q_3.2(1) #Feature covariates

#In the images above we can see the most imortant features. WE raited the importance by a metric which is the feature coeficiant multiplyed by the sd(feature). There is a direct connection between the coefficiant and the response. However if the sd of the variable is low then even with a high coefficiant the effect of the feature on the response is still low. We can not see a pattern between the features orientation or size. It seems to have multiple sizes, orientations and location in the image.

#Q_3.2(2) #Linearity of response: #In the plot above we can see that there does not seem to be a linear connectionperhaps since there are so many features no single feature is highly correlatedwith the with the response.

#Q_3.2(3) #The example domain

#The four lowest predictions do not have much seperaton lines in the oval space.most of the oval is an emty view and the main image takes only a small portion of oval.In compartment to the highest prediction set, the main part of the image takes up most, if not all, of the oval space.In highest set the images stand out individually with out any surrounding emptiness.

#Q_3.3